package com.ruoyi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.TAccount;
import com.ruoyi.service.ITAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 平台账户Controller
 * 
 * @author mzr
 * @date 2023-12-13
 */
@RestController
@RequestMapping("/system/account")
public class TAccountController extends BaseController
{
    @Autowired
    private ITAccountService tAccountService;

    /**
     * 查询平台账户列表
     */
   /* @PreAuthorize("@ss.hasPermi('system:account:list')")*/
    @GetMapping("/list")
    public TableDataInfo list(TAccount tAccount)
    {
        startPage();
        List<TAccount> list = tAccountService.selectTAccountList(tAccount);
        return getDataTable(list);
    }

    @GetMapping("/loadList")
    public TableDataInfo loadList(TAccount tAccount)
    {
        List<TAccount> list = tAccountService.selectTAccountList(tAccount);
        return getDataTable(list);
    }




    /**
     * 导出平台账户列表
     */
    @PreAuthorize("@ss.hasPermi('system:account:export')")
    @Log(title = "平台账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TAccount tAccount)
    {
        List<TAccount> list = tAccountService.selectTAccountList(tAccount);
        ExcelUtil<TAccount> util = new ExcelUtil<TAccount>(TAccount.class);
        util.exportExcel(response, list, "平台账户数据");
    }

    /**
     * 获取平台账户详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:account:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tAccountService.selectTAccountById(id));
    }

    /**
     * 新增平台账户
     */
    @PreAuthorize("@ss.hasPermi('system:account:add')")
    @Log(title = "平台账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAccount tAccount)
    {
        tAccount.setCreatTime(new Date());
        return toAjax(tAccountService.insertTAccount(tAccount));
    }

    /**
     * 修改平台账户
     */
    @PreAuthorize("@ss.hasPermi('system:account:edit')")
    @Log(title = "平台账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAccount tAccount)
    {
        tAccount.setChangeTime(new Date());
        return toAjax(tAccountService.updateTAccount(tAccount));
    }

    /**
     * 删除平台账户
     */
    @PreAuthorize("@ss.hasPermi('system:account:remove')")
    @Log(title = "平台账户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tAccountService.deleteTAccountByIds(ids));
    }

    @GetMapping("/getAllList")
    public List<TAccount> getAllList()
    {
        return tAccountService.selectAllList();
    }

}
